package com.acme.bankapp.domain.bank;

/**
 * Created by anton on 8/24/14.
 */
public class ClientBuilder {
    private String name;
    private Gender gender;
    private AbstractAccount account;

    private ClientBuilder() {
    }

    public static ClientBuilder newClient() {
        return new ClientBuilder();
    }

    public ClientBuilder withName(String name) {
        if (name == null || name.isEmpty()) {
            throw new IllegalArgumentException("Name should not be empty!");
        }
        this.name = name;
        return this;
    }

    public ClientBuilder male() {
        this.gender = Gender.MALE;
        return this;
    }

    public ClientBuilder female() {
        this.gender = Gender.FEMALE;
        return this;
    }

    public ClientBuilder withAccount(AbstractAccount account) {
        if (account == null) {
            throw new IllegalArgumentException("Account must be set!");
        }
        this.account = account;
        return this;
    }

    public Client build() {
        if (this.name == null || this.name.isEmpty()) {
            throw new IllegalArgumentException("Name should not be empty");
        }
        if (this.gender == null) {
            throw new IllegalArgumentException("Gender should be selected!");
        }
        if (this.account == null) {
            throw new IllegalArgumentException("Client should have an account");
        }
        return new Client(name, gender, account);
    }
}
